package com.gxa.meiye.admin.platform.controller;

import com.gxa.meiye.admin.platform.pojo.vo.*;
import com.gxa.meiye.admin.platform.service.WebUserService;
import com.gxa.meiye.core.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Api
@RestController
@RequestMapping("/platform/webUser")
public class WebUserController {

    @Autowired
    private WebUserService webUserService;

    @ApiOperation("平台端用户列表")
    @GetMapping("/userList")
    public Map selectWebUserList(){
        List<Map<String, Object>> maps = webUserService.webUserList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        System.out.println(maps);
        return jsonResult.getMap();
    }

    @ApiOperation("职位列表")
    @GetMapping("/roleList")
    public Map roleList(){
        List<String> strings = webUserService.roleList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(strings);
        return jsonResult.getMap();
    }

    @ApiOperation("新增平台用户")
    @PostMapping("/add")
    public Map add(@RequestBody AddWebUserVo userVo){
        Integer integer = webUserService.addWebUser(userVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @RequiresPermissions("user:select")
    @ApiOperation("查询用户")
    @PostMapping("/selectUsers")
    public Map selectUsers(String select){
        List<WebUserVo> userVos = webUserService.selectUsers(select);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(userVos);
        return jsonResult.getMap();
    }

    @ApiOperation("修改用户状态")
    @PostMapping("/updateStatus")
    public Map updateStatus(@RequestBody UpdateWebUserStatusVo userVo){
        webUserService.updateStatus(userVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("删除用户")
    @PostMapping("/delUsers")
    public Map delUsers(Integer id){
        webUserService.delUser(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("修改用户")
    @PostMapping("/updateUser")
    public Map updateUser(@RequestBody AddWebUserVo userVo){
        webUserService.updateUser(userVo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }
}
